//
// UIScrollView+SVInfiniteScrolling.h
//
// Created by Sam Vermette on 23.04.12.
// Copyright (c) 2012 samvermette.com. All rights reserved.
//
// https://github.com/samvermette/SVPullToRefresh
//
// Modified by https://github.com/harpher/SVPullToRefresh 12.03.13

#import <UIKit/UIKit.h>

typedef void (^SVInfiniteScrollingActionHandler)(void);
typedef UIEdgeInsets (^SVInfiniteScrollingExpectedContentInsetGetter)();
typedef CGFloat (^SVInfiniteScrollingExpectedTriggerOffsetGetter)();

@class SVInfiniteScrollingView;

@interface UIScrollView (SVInfiniteScrolling)

- (void)addInfiniteScrollingWithActionHandler:(SVInfiniteScrollingActionHandler)actionHandler
                   expectedContentInsetGetter:(SVInfiniteScrollingExpectedContentInsetGetter)expectedContentInsetGetter
                                   viewHeight:(CGFloat)viewHeight
                        expectedTriggerOffset:(CGFloat)expectedTriggerOffset;

- (void)clearAllInfiniteScrollingIssues;
- (void)triggerInfiniteScrolling;

@property (nonatomic, strong, readonly) SVInfiniteScrollingView *infiniteScrollingView;
@property (nonatomic, assign) BOOL showsInfiniteScrolling;
@property (nonatomic, assign) BOOL infiniteScrollingEnded;

@end


enum {
	SVInfiniteScrollingStateStopped = 0,
    SVInfiniteScrollingStateTriggered,
    SVInfiniteScrollingStateLoading,
    SVInfiniteScrollingStateEnded,
    SVInfiniteScrollingStateAll = 10
};

typedef NSUInteger SVInfiniteScrollingState;

@protocol SVInfiniteScrollingDelegate <NSObject>

@optional
- (void)infiniteScrollingView:(SVInfiniteScrollingView *)infiniteScrollingView
          stateDidChanged:(SVInfiniteScrollingState)state from:(SVInfiniteScrollingState)previousState;

@end

@interface SVInfiniteScrollingView : UIView

@property (nonatomic, readwrite) UIActivityIndicatorViewStyle activityIndicatorViewStyle;
@property (nonatomic, readonly) SVInfiniteScrollingState state;
@property (nonatomic, readwrite) BOOL enabled;

@property (nonatomic, readonly) CGFloat originalBottomInset;
@property (nonatomic, assign) CGFloat expectedTriggerOffset;

@property (nonatomic, strong) UIView <SVInfiniteScrollingDelegate> *customView;

- (BOOL)isAnimating;
- (void)startAnimating;
- (void)stopAnimating;

@end
